<?php
namespace app\api\controller;
use think\Db;
class Shop extends Base
{
    public function shopList() {
        $curr_page = input('post.page',1);
        $perpage = input('post.perpage',10);
        try {
            $whereShop = [
                ['del','=',0]
            ];
            $list = Db::table('mp_shop')
                ->where($whereShop)
                ->limit(($curr_page-1)*$perpage.",".$perpage)
                ->select();
        }catch (\Exception $e) {
            return ajax($e->getMessage(),-1);
        }
        $data = [
            'list' => $list
        ];
        return ajax($data);
    }

    public function tableList() {
        $post['shop_id'] = input('post.shop_id');
        checkPost($post);
        try {
            $whereShop = [
                ['t.del','=',0],
                ['t.status','=',1],
                ['t.shop_id','=',$post['shop_id']],
            ];
            $list = Db::table('mp_shop_table')->alias('t')
                ->join('mp_shop s','t.shop_id=s.id','left')
                ->where($whereShop)
                ->limit(0,50)
                ->field('t.id,t.table_no,t.shop_id,t.qrcode_value,s.status AS shop_status')
                ->select();
            if(empty($list)) {
                $shop_status = 2;
            }else {
                $shop_status = $list[0]['shop_status'];
            }
        }catch (\Exception $e) {
            return ajax($e->getMessage(),-1);
        }
        $data = [
            'shop_status' => $shop_status,
            'list' => $list
        ];
        return ajax($data);
    }

}